<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        window.onload = function () {
            let vm = new Vue({
                el: "#app",
                data() {
                    return {
                        msg: "hello world",
                        name: "zhangsan"
                    }
                },
                // 生命周期 钩子函数
                beforeCreate() {
                    console.log('vue实例初始化之前');
                },
                created() {
                    console.log('vue实例初始化好了,可以访问到数据模型中的数据以及methods方法');
                    console.log(this.msg);
                    this.sayName();
                },
                beforeMount() {
                    console.log('实例挂载之前');
                },
                mounted() {
                    console.log('实例挂载完毕，可以获取dom节点');
                },
                beforeUpdate() {
                    console.log('实例发生改变之前触发该生命周期');
                },
                updated() {
                    console.log('实例发生改变后页面视图发生变化,触发该生命周期');
                },
                beforeDestroy() {
                    console.log('实例销毁之前，仍然可以访问到数据模型中的数据和方法');
                    console.log(this.msg);
                    this.sayName();
                },
                destroyed() {
                    console.log('实例销毁完毕，销毁了监听器和事件监听以及子组件');
                    console.log(this.msg);
                    this.sayName();
                },
                methods: {
                    sayName() {
                        console.log(this.name);
                    }
                },
            });
            setTimeout(()=>{
                vm.msg='我被改变了'
            },3000)
        }
    </script>
</head>

<body>
    <div id="app">
        {{msg}}
    </div>
</body>

</html>